import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { useAppStore } from '@/store/modules/app'
import { useUserStore } from '@/store/modules/user'
import { useRouterStore } from '@/store/modules/router'
import { isExternalLink, pathToCamel } from '@/utils/tool'
import constant from '@/utils/constant'
import { useDictionaryStore } from '@/store/modules/dictionary'

NProgress.configure({ showSpinner: false })

const constantRoutes: RouteRecordRaw[] = [
	{
		path: '/redirect',
		component: () => import('../layout/index.vue'),
		children: [
			{
				path: '/redirect/:path(.*)',
				component: () => import('../layout/components/Router/Redirect.vue')
			}
		]
	},
	{
		path: '/iframe/:query?',
		component: () => import('../layout/components/Router/Iframe.vue')
	},
	{
		path: '/login',
		component: () => import('../views/login/index.vue')
	},
	{
		path: '/',
		component: () => import('../layout/index.vue'),
		children: [
			{
				path: '/bzjddetail',
				component: () => import('../views/bianzhi/shenhe/detail.vue')
			}
		]
	},
	{
		path: '/404',
		component: () => import('../views/404.vue')
	}
]

const asyncRoutes: RouteRecordRaw = {
	path: '/',
	component: () => import('../layout/index.vue'),
	redirect: '/dashboard/workbench',
	children: [
		{
			path: '/profile',
			name: 'ProfileIndex',
			component: () => import('../views/profile/index.vue'),
			meta: {
				title: '个人中心',
				cache: true
			}
		}
	]
}

// 配置控制台菜单
export const dashboardMenu = [
	{
		id: 100,
		name: '工作台',
		url: null,
		openStyle: 0,
		icon: 'icon-appstore',
		children: [
			// {
			// 	id: 101,
			// 	name: '首页',
			// 	url: 'dashboard/index',
			// 	openStyle: 0,
			// 	icon: 'icon-home',
			// 	affix: true
			// },
			{
				id: 102,
				name: '工作台',
				url: 'dashboard/workbench',
				openStyle: 0,
				icon: 'icon-appstore'
			}
		]
	},

	{
		id: 1,
		name: '工程标准管理',
		url: null,
		openStyle: 0,
		icon: 'icon-appstore',
		children: [
			{
				id: 1154,
				name: '标准项目管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 10001,
						name: '标准项目申报列表(申报)',
						url: 'Sproject/declare/index',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 10002,
						name: '标准项目申报列表(审核)',
						url: 'Sproject/audit/index',
						openStyle: 0,
						icon: 'icon-home'
					}
				]
			},

			{
				id: 2,
				name: '标准编制管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 201,
						name: '编制列表(申报)',
						url: 'bianzhi/shenbao/index',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 202,
						name: '编制列表(审核)',
						url: 'bianzhi/shenhe/index',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			},
			{
				id: 10010,
				name: '复审管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 10011,
						name: '复审列表(申报)',
						url: 'Reexamine/declare/index',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 10012,
						name: '年度复审清单',
						url: 'Reexamine/list/index',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 10013,
						name: '标准复审评分',
						url: 'Reexamine/score/index',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 10012,
						name: '复审列表(审核)',
						url: 'Reexamine/audit/index',
						openStyle: 0,
						icon: 'icon-home'
					}
				]
			},
			{
				id: 4,
				name: '标准应用管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 401,
						name: '宣贯培训',
						url: 'Standardapplication/train',
						openStyle: 0,
						icon: 'icon-home'
					},
					{
						id: 402,
						name: '咨询反馈',
						url: 'Standardapplication/feedback',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			},
			{
				id: 6,
				name: '前瞻性项目研究管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 601,
						name: '项目申报管理(申报)',
						url: 'Prospect-project/project-declare/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 602,
						name: '项目申报管理(审核管理)',
						url: 'Prospect-project/project-examine/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 603,
						name: '项目过程管理',
						url: 'Prospect-project/Project-process/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 604,
						name: '项目过程管理(审核管理)',
						url: 'Prospect-project/Project-process-audit/index',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			},
			{
				id: 63,
				name: '标准库管理',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore',

				children: [
					{
						id: 64,
						name: '标准库维护列表',
						url: 'Standard/maintenance/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},

					{
						id: 68,
						name: '标签分类维护',
						url: null,
						openStyle: 0,
						icon: 'icon-appstore',
						children: [
							{
								id: 100221,
								name: '基础分类标签',
								url: 'Standard/tag/base',
								openStyle: 0
							},
							{
								id: 100222,
								name: '专题分类标签',
								url: 'Standard/tag/special',
								openStyle: 0
							},
							{
								id: 100223,
								name: '标准等级标签',
								url: 'Standard/tag/grade',
								openStyle: 0
							},
							{
								id: 100224,
								name: '强制性分类标签',
								url: 'Standard/tag/mandatory',
								openStyle: 0
							},
							{
								id: 100225,
								name: '管理条线标签',
								url: 'Standard/tag/managementLine',
								openStyle: 0
							},
							{
								id: 100226,
								name: '工程专业分类标签',
								url: 'Standard/tag/engineering',
								openStyle: 0
							},
							{
								id: 100227,
								name: '工程全生命周期分类标签',
								url: 'Standard/tag/engineeringLifecycle',
								openStyle: 0
							},
							{
								id: 100228,
								name: '建筑类型分类标签',
								url: 'Standard/tag/buildingType',
								openStyle: 0
							},
							{
								id: 100229,
								name: '标准状态标签',
								url: 'Standard/tag/standardState',
								openStyle: 0
							},
							{
								id: 1002211,
								name: '编制状态分类标签',
								url: 'Standard/tag/compilation',
								openStyle: 0
							},
							{
								id: 1002212,
								name: '术语标签',
								url: 'Standard/tag/term',
								openStyle: 0
							},
							{
								id: 1002213,
								name: '条文标签(专业)',
								url: 'Standard/tag/articleMajor',
								openStyle: 0
							},
							{
								id: 1002214,
								name: '条文标签(管理)',
								url: 'Standard/tag/articleManage',
								openStyle: 0
							},
							{
								id: 1002215,
								name: '标准国际化领域标签',
								url: 'Standard/tag/internationalization',
								openStyle: 0
							},
							{
								id: 1002216,
								name: '热门领域标签',
								url: 'Standard/tag/hotAreas',
								openStyle: 0
							}
						]
					},

					{
						id: 84,
						name: '体系汇总表',
						url: 'Standard/summary/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 85,
						name: '系统日志',
						url: 'Standard/log/index',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			},

			{
				id: 10030,
				name: '政务公开',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 10041,
						name: '宣贯计划',
						url: 'Governmentgongkai/xuanguan',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10042,
						name: '通知发布',
						url: 'Governmentgongkai/notice',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10043,
						name: '政策性文件',
						url: 'Governmentgongkai/wenjianfabu',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10044,
						name: '查看内容',
						url: 'Governmentgongkai/view',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10051,
						name: '强制性条文实施情况(仅验收)',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10052,
						name: '问卷设置(仅验收)',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 10053,
						name: '问卷回复(仅验收)',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					}

					// {
					// 	id: 10044,
					// 	name: '文件查看',
					// 	url: 'Governmentgongkai/xuanguan',
					// 	openStyle: 0,
					// 	icon: 'icon-appstore'
					// },
					// {
					// 	id: 100145,
					// 	name: '强制性条文实施',
					// 	url: 'Standardapplication/feedback',
					// 	openStyle: 0,
					// 	icon: 'icon-appstore'
					// },
					// {
					// 	id: 10046,
					// 	name: '问卷设置和调查',
					// 	url: 'Standardapplication/feedback',
					// 	openStyle: 0,
					// 	icon: 'icon-appstore'
					// }
				]
			},

			{
				id: 109,
				name: '团体标准管理',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 901,
						name: '团体标准录入',
						url: 'Group/enter/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 902,
						name: '团体标准的审核',
						url: 'Group/audit/index',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 903,
						name: '团体标准工程应用信息采集',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 904,
						name: '团体标准工程应用信息审核发布',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			},

			{
				id: 115,
				name: '标准国际化管理',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore',

				children: [
					{
						id: 901,
						name: '国际化标准信息采集发布',
						url: 'international/add/index',
						openStyle: 0,
						icon: 'icon-home'
					}
					// {
					// 	id: 902,
					// 	name: '团体标准的审核',
					// 	url: 'international/examine/index',
					// 	openStyle: 0,
					// 	icon: 'icon-appstore'
					// }
				]
			},

			{
				id: 123,
				name: '长三角标准管理',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore',

				children: [
					{
						id: 901,
						name: '长三角标准信息采集发布',
						url: 'Changjiangdelta/add/index',
						openStyle: 0,
						icon: 'icon-appstore'
					}
					// {
					// 	id: 902,
					// 	name: '团体标准的审核',
					// 	url: 'Changjiangdelta/examine/index',
					// 	openStyle: 0,
					// 	icon: 'icon-appstore'
					// }
				]
			},
			{
				id: 131,
				name: '统计分析',
				url: 'Statistica/index',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 133,
				name: '系统维护',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore',

				children: [
					{
						id: 2333,
						name: '时间设定',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2334,
						name: '账号分配',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2335,
						name: '用户清单',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2341,
						name: '主管单位',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2336,
						name: '阶段附件',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2337,
						name: '模板文件',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2338,
						name: '阶段附件',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					},
					{
						id: 2340,
						name: '角色权限配置',
						url: '',
						openStyle: 0,
						icon: 'icon-appstore'
					}
				]
			}
		]
	},

	{
		id: 2440,
		name: '系统设置',
		url: null,
		openStyle: 0,
		icon: 'icon-setting',
		children: [
			{
				id: 2441,
				name: '截止时间设定',
				url: 'system/deadlineTime/index',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2442,
				name: '账号分配',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2443,
				name: '用户清单',
				url: 'system/user/index',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2444,
				name: '主管单位',
				url: 'system/unit/index',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2445,
				name: '模板文件',
				url: 'system/Templatefile/index',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2446,
				name: '阶段附件',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore'
			},
			{
				id: 2447,
				name: '角色权限配置',
				url: null,
				openStyle: 0,
				icon: 'icon-appstore',
				children: [
					{
						id: 24471,
						name: '角色配置',
						url: 'system/rbac/role',
						openStyle: 0,
						icon: ''
					},
					{
						id: 24472,
						name: '权限配置',
						url: 'system/rbac/perm',
						openStyle: 0,
						icon: ''
					}
				]
			},
			{
				id: 2448,
				name: '操作日志',
				url: '',
				openStyle: 0,
				icon: 'icon-appstore'
			}
		]
	}
	// {
	// 	id: 10020,
	// 	name: '标准库管理',
	// 	url: null,
	// 	openStyle: 0,
	// 	icon: 'icon-appstore',
	// 	children: [
	// 		{
	// 			id: 10021,
	// 			name: '标准库维护',
	// 			url: 'Standard/maintenance/index',
	// 			openStyle: 0,
	// 			icon: 'icon-home',
	//
	// 		},
	// 		{
	// 			id: 10022,
	// 			name: '标签分类维护',
	// 			url: null,
	// 			openStyle: 0,
	// 			icon: 'icon-home',
	// 			children: [
	// 				{
	// 					id: 100221,
	// 					name: '基础分类标签',
	// 					url: 'Standard/tag/base',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100222,
	// 					name: '专题分类标签',
	// 					url: 'Standard/tag/special',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100223,
	// 					name: '标准等级标签',
	// 					url: 'Standard/tag/grade',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100224,
	// 					name: '强制性分类标签',
	// 					url: 'Standard/tag/mandatory',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100225,
	// 					name: '管理条线标签',
	// 					url: 'Standard/tag/managementLine',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100226,
	// 					name: '工程专业分类标签',
	// 					url: 'Standard/tag/engineering',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100227,
	// 					name: '工程全生命周期分类标签',
	// 					url: 'Standard/tag/engineeringLifecycle',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100228,
	// 					name: '建筑类型分类标签',
	// 					url: 'Standard/tag/buildingType',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 100229,
	// 					name: '标准状态标签',
	// 					url: 'Standard/tag/standardState',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002211,
	// 					name: '编制状态分类标签',
	// 					url: 'Standard/tag/compilation',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002212,
	// 					name: '术语标签',
	// 					url: 'Standard/tag/term',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002213,
	// 					name: '条文标签(专业)',
	// 					url: 'Standard/tag/articleMajor',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002214,
	// 					name: '条文标签(管理)',
	// 					url: 'Standard/tag/articleManage',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002215,
	// 					name: '标准国际化领域标签',
	// 					url: 'Standard/tag/internationalization',
	// 					openStyle: 0,
	//
	// 				},
	// 				{
	// 					id: 1002216,
	// 					name: '热门领域标签',
	// 					url: 'Standard/tag/hotAreas',
	// 					openStyle: 0,
	//
	// 				}
	// 			]
	// 		},
	// 		{
	// 			id: 10023,
	// 			name: '体系汇总表',
	// 			url: 'Standard/summary/index',
	// 			openStyle: 0,
	// 			icon: 'icon-home',
	//
	// 		},
	// 		{
	// 			id: 10024,
	// 			name: '系统日志',
	// 			url: 'Standard/log/index',
	// 			openStyle: 0,
	// 			icon: 'icon-home',
	//
	// 		}
	// 	]
	// },

	// {
	// 	id: 7,
	// 	name: '前瞻性研究项目编制管理',
	// 	url: null,
	// 	openStyle: 0,
	// 	icon: 'icon-appstore',
	// 	children: [
	// 		{
	// 			id: 701,
	// 			name: '前瞻性研究项目编制',
	// 			url: '',
	// 			openStyle: 0,
	// 			icon: 'icon-home',
	//
	// 		},
	// 		{
	// 			id: 702,
	// 			name: '前瞻性研究项目编制过程审核',
	// 			url: '',
	// 			openStyle: 0,
	// 			icon: 'icon-appstore'
	// 		}
	// 	]
	// },
]

// 配置常量菜单
export const constantMenu = [
	{
		id: 1000,
		name: 'Demo',
		url: null,
		openStyle: 0,
		icon: 'icon-windows',
		children: [
			{
				id: 1001,
				name: 'Icon 图标',
				url: 'demo/icons/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1002,
				name: '二维码生成',
				url: 'demo/qrcode/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1003,
				name: '页面打印',
				url: 'demo/printJs/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1004,
				name: '图片裁剪',
				url: 'demo/cropper/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1005,
				name: '富文本编辑器',
				url: 'demo/editor/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1006,
				name: 'Markdown',
				url: 'demo/markdown/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1007,
				name: 'ECharts图表',
				url: 'demo/echarts/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			},
			{
				id: 1008,
				name: 'WebSocket',
				url: 'demo/websocket/index',
				openStyle: 0,
				icon: 'icon-unorderedlist'
			}
		]
	}
]

export const errorRoute: RouteRecordRaw = {
	path: '/:pathMatch(.*)',
	redirect: '/404'
}

export const router = createRouter({
	history: createWebHistory(),
	routes: constantRoutes
})

// 白名单列表
const whiteList = ['/login']

// 路由跳转前
router.beforeEach(async (to, from, next) => {
	NProgress.start()

	const appStore = useAppStore()
	const userStore = useUserStore()
	const routerStore = useRouterStore()
	const dictionaryStore = useDictionaryStore()
	//console.log(userStore.token,"s22222222222222gsgsgsg")
	// token存在的情况
	if (userStore.token) {
		//	console.log(222222)
		///console.log(to.path,"sgsgs3gsg")
		if (to.path === '/login') {
			next(constant.loginPage)
		} else {
			///	console.log(444444444444,userStore.user.id)

			// 用户信息不存在，则重新拉取
			if (!userStore.user.id) {
				await dictionaryStore.initDictionary()
				try {
					await userStore.getUserInfoAction()
					//	await userStore.getAuthorityListAction()
					//	await appStore.getDictListAction()
				} catch (error) {
					// 请求异常，则跳转到登录页
					userStore?.setToken('')
					next('/login')
					return Promise.reject(error)
				}

				// 动态菜单+常量菜单
				const menuRoutes = await routerStore.getMenuRoutes()
				// const menuRoutes=constantMenu1

				//  console.log(menuRoutes,"menuRoutes")

				// 获取扁平化路由，将多级路由转换成一级路由
				const keepAliveRoutes = getKeepAliveRoutes(menuRoutes, [])

				// 添加菜单路由
				asyncRoutes.children?.push(...keepAliveRoutes)
				router.addRoute(asyncRoutes)

				// 错误路由
				router.addRoute(errorRoute)

				// 保存路由数据
				routerStore.setRoutes(constantRoutes.concat(asyncRoutes))

				// 搜索菜单需要使用
				routerStore.setSearchMenu(keepAliveRoutes)

				next({ ...to, replace: true })
			} else {
				next()
			}
		}
	} else {
		// 没有token的情况下，可以进入白名单
		if (whiteList.indexOf(to.path) > -1) {
			///console.log('sd')
			next()
		} else {
			if (to.fullPath === '/') {
				next('/login')
			} else {
				next(`/login?redirect=${to.fullPath}`)
			}
		}
	}
})

// 路由加载后
router.afterEach(() => {
	NProgress.done()
})

// 获取扁平化路由，将多级路由转换成一级路由
export const getKeepAliveRoutes = (rs: RouteRecordRaw[], breadcrumb: string[]): RouteRecordRaw[] => {
	const routerList: RouteRecordRaw[] = []

	rs.forEach((item: any) => {
		if (item.meta.title) {
			breadcrumb.push(item.meta.title)
		}

		if (item.children && item.children.length > 0) {
			routerList.push(...getKeepAliveRoutes(item.children, breadcrumb))
		} else {
			item.meta.breadcrumb.push(...breadcrumb)
			routerList.push(item)
		}

		breadcrumb.pop()
	})
	return routerList
}

// 加载vue组件
export interface ModuleMap {
	[key: string]: any
}

export const layoutModules = () => {
	return import.meta.glob('/src/views/**/*.vue')
}

// 根据路径，动态获取vue组件
const getDynamicComponent = (path: string): any => {
	const modules: ModuleMap = layoutModules()
	return modules[`/src/views/${path}.vue`]
}

// 根据菜单列表，生成路由数据
export const generateRoutes = (menuList: any): RouteRecordRaw[] => {
	const routerList: RouteRecordRaw[] = []

	menuList.forEach((menu: any) => {
		let component
		let path
		if (menu.children && menu.children.length > 0) {
			component = () => import('@/layout/index.vue')
			path = '/p/' + menu.id
		} else {
			// 判断是否iframe
			if (isIframeUrl(menu)) {
				component = () => import('@/layout/components/Router/Iframe.vue')
				path = '/iframe/' + menu.id
			} else {
				component = getDynamicComponent(menu.url)
				path = '/' + menu.url
			}
		}
		const route: RouteRecordRaw = {
			path: path,
			name: pathToCamel(path),
			component: component,
			children: [],
			meta: {
				title: menu.name,
				icon: menu.icon,
				id: '' + menu.id,
				url: menu.url,
				cache: true,
				newOpen: menu.openStyle === 1,
				affix: menu.affix,
				breadcrumb: []
			}
		}

		// 有子菜单的情况
		if (menu.children && menu.children.length > 0) {
			route.children?.push(...generateRoutes(menu.children))
		}

		routerList.push(route)
	})

	return routerList
}

// 判断是否iframe
const isIframeUrl = (menu: any): boolean => {
	// 如果是新页面打开，则不用iframe
	if (menu.openStyle === 1) {
		return false
	}

	// 是否外部链接
	return isExternalLink(menu.url)
}
